<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
%>
<html lang="zh-cn">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>  
    <link rel="stylesheet" href="<%=path %>/admin/css/pintuer.css">
    <link rel="stylesheet" href="<%=path %>/admin/css/admin.css">
    <link rel="stylesheet" href="<%=path %>/admin/css/style.css">
    <link rel="stylesheet" href="<%=path %>/admin/font-awesome-4.7.0/css/font-awesome.css">
    <script src="<%=path %>/admin/js/jquery.js"></script>
    <script src="<%=path %>/admin/js/pintuer.js"></script>  
    <link rel="stylesheet" href="<%=path %>/static/css/paging.css" />
    <script src="<%=path %>/static/js/paging.js"></script> 
</head>
<body>
<form method="post" action="<%=path %>/admin/toUpdate" id="listform">
  <input type="hidden" id="totalSize" name="totalSize" value="${planSum}">
  <input type="hidden" id="pageNo" name="pageNo" value="${pageNo}">
  <input type="hidden" id="pageSum" name="pageSum" value="${pageSum}">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 管理员列表</strong> 
    <td colspan="7" style="text-align:left;padding-left:20px;"><a href="javascript:void(0)" class="button border-blue icon-edit" style="padding:5px 15px;margin-left:30px;" onclick="addAdmin()"> 新增管理员</a>
    <a href="<%=path %>/admin/toAdd" style="float:right; display:none;" >新增管理员</a></div>
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <!-- <li>
          <input type="text" placeholder="请输入搜索关键字" name="keywords" id="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a></li> -->
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr class="thead">
        <th style="text-align:left; padding-left:20px;width:8%">序号</th>
        <th style="width:10%">姓名</th>
        <th style="width:10%">登录名</th>
        <th style="width:10%">电话</th>
        <th style="width:10%">部门</th>
        <th style="width:10%">邮箱</th>
        <th style="width:10%">角色</th>
        <th width="10%">创建时间</th>
        <th width="10%">操作</th>
       <!--  <th width="10%">状态</th>
        <th width="310">操作</th> -->
      </tr>
      	 <c:forEach items="${adminList }" var="list" varStatus="vs">
              	<tr class="fir">
		          <td id="adminId" style="text-align:left; padding-left:20px;">
		          <c:if test="${list.adRole!='HIGH'}">
		          <input type="checkbox" name="id[]" value="${list.adId}" />
		          </c:if>
		           ${vs.count+pageInfo.startIndex+(pageNo-1)*15}</td>
		          <td>${list.adName }</td>
		          <td>${list.adUser }</td>
		          <td>${list.adPhone }</td>
		          <td>${list.adDepartment }</td>
		          <td>${list.adEmail}</td>
		          <c:choose>
                  <c:when test="${list.adName=='ad'}"><td>系统管理员</td></c:when>
                  <c:otherwise><td>普通管理员</td></c:otherwise>
                 </c:choose>
		          <td><fmt:formatDate value="${list.adCreateTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
		          <td><div class="suspended-pos"><i class="fa fa-edit" onclick="update(${list.adId})"></i><span class="suspended">修改</span></div>
		         <c:choose>
                  <c:when test="${list.adDeleteState==1}"> <div class="suspended-pos"><i class="fa fa-unlock-alt state" openid="${list.adId}" state="1" onclick="javascript:state1(this)"><span class="suspended" >禁用</span></i></div></c:when>
                  <c:otherwise><div class="suspended-pos"><i class="fa fa-unlock state" openid="${list.adId}" state="0" onclick="javascript:state1(this)"><span class="suspended">启用</span></i></div></c:otherwise>
                 </c:choose>
                  <c:if test="${list.adRole!='HIGH'}">
                  <div class="suspended-pos"><i class="fa fa-bars" onclick="resource(${list.adId})"></i><span class="suspended">权限</span></div>
                  </c:if>
		          </td> 
		        </tr>	
              </c:forEach>
       <tr>
	     <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checkall"/>全选 </td>
	     <td colspan="8" style="text-align:left;padding-left:20px;"><a href="javascript:updateresource()" class="button border-red" style="padding:5px 15px;">分配资源</a></td>
      </tr>
      <tr>
            <td colspan="8">
                <div id="page" class="page_div"></div>
            </td>
      </tr>
    </table>
  </div>
</form>
<script type="text/javascript" src="<%=path%>/admin/js/layer/layer.js" ></script>
<script type="text/javascript">
	var paths = '<%=path %>';
	var pageNo = Number($("#pageNo").val());
	var totalSize = Number($("#totalSize").val());
	var totalPage = Number($("#pageSum").val());
	$(function(){
        var uTag = '${upTag}';
        if(uTag >= 1){
            layer.msg('修改操作成功！');
        }else if(uTag == -1){
            layer.msg('系统忙,请稍后重试...');
        }
	    page(pageNo,totalPage,totalSize);
	})
	//分页
	function page(pageNo,totalPage,totalSize){
	    $("#page").paging({
	        pageNo:pageNo,//当前页
	        totalPage: totalPage,//总页数
	        totalSize: totalSize,//总条数
	        callback: function(num) {
	            newPage(num); 
	       }
	    })
	}
//newPage or search
function newPage(pageNo,key){
	var params = new Object();
	params.pageNo = pageNo-1;
	$.ajax({ 
		type:"post",
		url:"<%=path %>/devops/newPage",
		data:params,
		dataType: "json",  
        timeout: 10000,  
        cache: false,  
        error: function(){
        	alert("系统忙...");
        },
        success: function(data){
        	var json=eval(data);
        	pageNo = json.pageNo;
        	pageSum = json.pageSum;
        	count=json.count;
        	var htmls = "";
       	 $.each(json.adminList, function (index, item) { 
       		 var xu=(pageNo)*15+index+1;
               htmls += '<tr class="fir">'
					 +'<td id="planId" style="text-align:left; padding-left:20px;">'
					 if(item.adRole=="HIGH"){
						 htmls+=xu+'</td>'
					 }else{
						 htmls+='<input type="checkbox" name="id[]" value="'+item.adId+'" />'+xu+'</td>'
					 }	
			    htmls+='<td>'+item.adName+'</td>'
					 +'<td>'+item.adUser+'</td>'
					 +'<td>'+item.adPhone+'</td>'
					 +'<td>'+item.adDepartment+'</td>'
					 +'<td>'+item.adEmail+'</td>'
					 if(item.adRole=="HIGH"){
                         htmls+='<td>系统管理员</td>'
                     }else{
                         htmls+='<td>普通管理员 </td>'
                     }  
			    htmls+='<td>'+getNowFormatDate(item.adCreateTime)+'</td>';
				htmls+='<td><div class="suspended-pos"><i class="fa fa-edit" onclick="update('+item.adId+')"></i><span class="suspended">修改</span></div>';	
				if(item.adDeleteState==1){
                    htmls+='<div class="suspended-pos"><i class="fa fa-unlock-alt state" openid="'+item.adId+'" onclick="state1(this)" state="1"><span class="suspended" >禁用</span></i></div>';
                }else{
                    htmls+='<div class="suspended-pos"><i class="fa fa-unlock state" openid="'+item.adId+'" onclick="state1(this)" state="0"><span class="suspended">启用</span></i></div>';
                }
				if(item.adRole!="HIGH"){
					 htmls+='<div class="suspended-pos"><i class="fa fa-bars" onclick="resource('+item.adId+')"></i><span class="suspended">权限</span></div>'
	            }
				htmls+='</td></tr>';
         });
       	 $(".fir").remove();
       	 $(".thead").after(htmls);
       	 if(htmls==""){
             //$("#page").html("");
         }else{
             $("#page").html("");
            $("#page").paging({
                 pageNo:pageNo,//当前页
                 totalPage: pageSum,//总页数
                 totalSize: count,//总条数
                 callback: function(num) {
                     newPage(num); 
                }
             })
          }
        }   
	});
}
//修改
function update(obj){
	/* var id = $(obj).closest(".fir").find("#adminId").text().trim(); */
	window.location.href="<%=path %>/devops/toUpdate?adminId="+obj;
}

function state1(obj) {
	var state=$(obj).attr("state");
	var openid=$(obj).attr("openid");
	if(confirm("您确定要"+(state==1?"禁用":"启用")+"吗?")){
	    $.ajax({
	        url : paths + "/devops/updateState",
	        type : "POST",
	        dataType : "json",
	        data : {
	            "state" : state==1?0:1,
	            "id" : openid
	        },
	        success : function(data) {
	            if(state==1){
	                $(obj).attr("class","fa fa-unlock state")
	                $(obj).html("<span class='suspended'>启用</span>");
	                $(obj).attr("state","0");
	            }else{
	                $(obj).attr("class","fa-unlock-alt state")
	                $(obj).html("<span class='suspended'>禁用</span>");
	                $(obj).attr("state","1");
	            }
	        },
	        error : function(r, s, m) {
	        }
	    });
	   }
  }
function addAdmin(){
	window.location.href = "<%=path %>/devops/toAdd";
}

function resource(id){
    var arrayObj = new Array();
    arrayObj.push(id);
    layer.open({
        type: 2,
        title: '分配资源',
        shadeClose: false,
        shade: 0.6,//遮罩透明度
        move:false,
        area: ['400px', '350px'],
        content: paths+'/devops/resource?args='+arrayObj,
        end: function(index){
            window.location.href="<%=path %>/devops/list";
        }
      });  
}

//分配资源	
function updateresource(){
     var arrayObj = new Array();  
     var Checkbox=false;
     $("input[name='id[]']").each(function(){
      if (this.checked==true) {
        arrayObj.push($(this).val()); 
        Checkbox=true;  
      }
     });
     if(Checkbox){
         layer.open({
             type: 2,
             title: '分配资源',
             shadeClose: false,
             shade: 0.6,//遮罩透明度
             move:false,
             area: ['400px', '350px'],
             content: paths+'/devops/resource?args='+arrayObj,
             end: function(index){
                 window.location.href="<%=path %>/devops/list";
             }
           });          
    }
    else{
        alert("请选择您要分配资源的用户!");
        return false;
    }
    
}	
	
	
 function getNowFormatDate(time) {
	    var date = new Date(time);
	    var seperator1 = "-";
	    var seperator2 = ":";
	    var year = date.getFullYear();
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 0 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    var h = 0;
	    if (date.getHours() >= 0 && date.getHours() <= 9) {
	        h = "0" + date.getHours();
	    }else{
	    	h = date.getHours();
	    }
	    var m = 0;
	    if (date.getMinutes() >= 0 && date.getMinutes() <= 9) {
	        m = "0" + date.getMinutes();
	    }else{
	    	m = date.getMinutes();
	    }
	    var s = 0;
	    if (date.getSeconds() >= 0 && date.getSeconds() <= 9) {
	        s = "0" + date.getSeconds();
	    }else{
	    	s = date.getSeconds();
	    }
	    var currentdate = year + seperator1 + month + seperator1 + strDate
	            + " " + h + seperator2 + m
	            + seperator2 + s;
	    return currentdate;
	}
 
//全选
 $("#checkall").click(function(){ 
   $("input[name='id[]']").each(function(){
       if (this.checked) {
           this.checked = false;
       }
       else {
           this.checked = true;
       }
   });
 })

</script>
</body>
</html>